const { runtime } = require("webpack");

module.exports = (api) => {
  // 实现 csr ssr
  const isWeb = api.caller(caller => caller && caller.target === 'isWeb');
  return {
    // env typescript transform-runtime loadable aplitting 代码分割
    presets: [
      [
        "@babel/env",
        {
          useBuiltIns: isWeb ? 'usage': undefined,
          corejs: isWeb ? 3 : false,
        },
      ],
      "@babel/typescript",
      [
        "@babel/react",
        {
          runtime: 'automatic'
        }
      ]
    ],
    plugins: ["@babel/babel-plugin", "@babel/plugin-transform-runtime"],
    env: {
      development: {
        plugins: isWeb ? ["react-refresh/babel"] : undefined
      }
    }
  }
}
